 $(function() {
			initPager();
		});

		function initPager(){
			$("#Pagination").pagination(totalResult, {
                callback: function(new_page_index, pagination_container){
                	var oldLocation = location.href;
                	var pa = "currentPage=" + (new_page_index+1);
            		var shoC = "showCount=" + showCount;
                	var index = oldLocation.lastIndexOf("?");
                	if (index == -1){
                		location.href = oldLocation + "?" + pa + "&" + shoC;
                	}else if (oldLocation.indexOf("currentPage") == -1){
                		location.href = oldLocation + "&" + pa;
                	}else if (oldLocation.indexOf("showCount") == -1){
                		location.href = oldLocation + "&" + shoC;
                	}else{
                		var temp = oldLocation.replace(/currentPage=\d+/, pa);
						var newLocation = temp.replace(/showCount=\d+/, shoC);
                		location.href = newLocation;
                	}
                	return false;
                },
                items_per_page:showCount, 
                load_first_page:false,
                prev_text:'上一页',
                next_text:'下一页',
                ellipse_text:'...',
                num_edge_entries:1,
                num_display_entries:5,
                current_page:currentPage,
            });
		}
		
		/*
 		批量下架商品
	*/
	function batchOutGoods(status){
		var goodsIds = $("input[name='goodsIds']:checked");
		if (goodsIds.length <= 0){
			var msg = '';
			if (status == 2){
				msg = '请勾选要下架的商品';
				layer.tips(msg, '#batchBtn');
			}
			if (status == 1){
				msg = '请勾选要上架的商品';
				layer.tips(msg, '#batchBtn2');
			}
			return ;
		}
		var data = "";
		for (var i = 0; i < goodsIds.length; i++){
			if (i == 0){
				data += "goodsIds=" + goodsIds[i].value; 
			}else{
				data += "&goodsIds=" + goodsIds[i].value; 
			}
		}
		data += "&status="+status;
		
		$.post(base_path+"/backstage/goods-batch-out", data)
		.done(function(data){
			if (data.error == "0000"){
				layer.msg(data.information,{icon:6});
				$(".btn-refresh").click();
			}else{
				layer.msg(data.information,{icon:5});
			}
		})
	}
		
		/*
		重置
		*/
		function theReset(){
			$("#search-form input[type='text']").val('');
			$("#search-form select").val(-1);
			$("#endType").val("-1");
		}
			
		
		/* /*添加*/
		function goods_add(title,url){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		} 
		/*编辑*/
		function goods_edit(obj,id,w,h){
			isZiYing = $("#isZiYing").val();
			var edit_page = base_path+"/backstage/goods-add-pre?isZiYing="+isZiYing+"&id="+id;
			var index = layer.open({
				type: 2,
				title: "编辑商品",
				content: edit_page
			});
			layer.full(index);
			//layer_show("编辑商品",edit_page,w,h);
		}
		/*查看*/
		function goods_show(title,url,id){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		}
		/*删除*/
		function goods_disable(obj,id){
			layer.confirm('确认删除？', {
				btn: ['确认','取消'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : base_path+"/backstage/goods-disable",
					data : "id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
						$(obj).parents("body").find(".btn-refresh").click();
					}
				});
			},
			function(){
				layer.msg('未删除', {icon:5,time:1000});
			});	
		}
		/*审核*/
		function product_shenhe(obj,id){
			layer.confirm('审核文章？', {
				btn: ['通过','不通过'], 
				shade: false
			},
			function(){
				$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
				$(obj).remove();
				layer.msg('已发布', {icon:6,time:1000});
			},
			function(){
				$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
				$(obj).remove();
				layer.msg('未通过', {icon:5,time:1000});
			});	
		}
		/*下架*/
		function product_stop(obj,id){
			layer.confirm('确认要下架吗？',function(index){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				layer.msg('已下架!',{icon: 5,time:1000});
			});
		}

var type1;
var type2;
var type3;		
function firstChange(theSelect){
			var typeId = theSelect.value;

			if (!type2){
				$.ajax({
					type:"post",
					async:false,
					url:base_path+"/backstage/get-types",
					data : {level:2,isZiYing:true},
					success : function(msg){
						type2 = msg;
					}
					});
				}
			var options = "<option value='-1'>--中类--</option>";
			for (var i = 0; i < type2.length; i++){
				if (typeId == type2[i].cBelong){
					var aOption = "<option value='"+type2[i].cCode+"' >"+type2[i].cName+"</option>"
					options += aOption; 
				}
			}
			$("#type2").html(options);
		}
	function secondChange(theSelect){
	var typeId = theSelect.value;

	if (!type3){
		$.ajax({
			type:"post",
			async:false,
			url:base_path+"/backstage/get-types",
					data : {
						level : 3,
						isZiYing : true
					},
					success : function(msg) {
						type3 = msg;
					}
				});
			}
			var options = "<option value='-1'>--小类--</option>";
			for (var i = 0; i < type3.length; i++) {
				if (typeId == type3[i].cBelong) {
					var aOption = "<option value='"+type3[i].cCode+"' >"
							+ type3[i].cName + "</option>"
					options += aOption;
				}
			}
			$("#type3").html(options);
		}

		function beforSubmit() {
			var type1 = $("#type1").val();
			var type2 = $("#type2").val();
			var type3 = $("#type3").val();

			var endType = -1;
			if (type3 != -1) {
				endType = type3;
			} else if (type2 != -1) {
				endType = type2;
			} else if (type1 != -1) {
				endType = type1;
			}
			$("#endType").val(endType);
			return true;
		} 